/**
 * 
 */
package com.neal.web.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.neal.domain.securities.Function;
import com.neal.domain.securities.User;


/**
 * @author Neal
 * @version 1.0
 * @description 
 */
@Controller
@RequestMapping("/json")
public class JsonController {
	
	@ResponseBody
	@RequestMapping("do1")
	public String do1() {
		return "do1";
	}
	
	@RequestMapping("do2")
	public ResponseEntity<String> do2(){
			// do something with request header and body
			HttpHeaders responseHeaders = new HttpHeaders();
			responseHeaders.set("MyResponseHeader", "MyValue");
			return new ResponseEntity<String>("Hello World", responseHeaders, HttpStatus.CREATED);
	}
	
	@RequestMapping("do3")
	public @ResponseBody User do3() {
		User u = new User();
		u.setUserId("3");
		u.setPassword("33333");
		return u;
	}
	
	@RequestMapping("do4")
	@ResponseBody
	public User do4() {
		User u = new User();
		u.setUserId("4");
		u.setPassword("444444");
		return u;
	}
	@RequestMapping("do5")
	@ResponseBody
	public List<User> do5(){
		User u1 = new User();
		u1.setUserId("1");
		u1.setPassword("11");
		
		User u2 = new User();
		u2.setUserId("2");
		u2.setPassword("22");
		
		List<User> users = new ArrayList<User>();
		users.add(u1);
		users.add(u2);
		return users;
	}
	
	@RequestMapping("do6")
	@ResponseBody
	public List<User> do6(){
		User u1 = new User();
		u1.setUserId("6");
		u1.setPassword("67");
		
		User u2 = new User();
		u2.setUserId("7");
		u2.setPassword("77");
		
		List<User> users = new ArrayList<User>();
		users.add(u1);
		users.add(u2);
		return new ArrayList<User>(users);
	}
	
	@RequestMapping("do7")
	@ResponseBody
	public Map<String,Object> do7(){
		User u1 = new User();
		u1.setUserId("7");
		u1.setPassword("7");
		
		Function function = new Function();
		function.setName("00");
		
		Map<String, Object>map = new HashMap<String,Object>();
		map.put("user", u1);
		map.put("function", function);
		
		return map;
	}
}
